package org.bird.jvm;

import java.util.ArrayList;
import java.util.List;

/**
 * @Described：常量池内存溢出探究 
 * @VM args : -XX:PermSize=10M -XX:MaxPermSize=10M -XX:+PrintGCDetails -XX:+UseConcMarkSweepGC -XX:+HeapDumpOnOutOfMemoryError
 * @author liangjf
 *
 */
public class ConstantOutOfMemory {

	public static void main(String[] args) throws Exception {
		try {
			//使用List保持着常量池引用，避免Full GC回收常量池行为
			List<String> strings = new ArrayList<String>();
			int i = 0;
			while (true) {
				strings.add(String.valueOf(i++).intern());
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}
}
